package com.marchsoft.dao;

import com.marchsoft.common.mapper.CommentMapper;
import com.marchsoft.domain.Student;
import com.marchsoft.domain.Teacher;
import com.marchsoft.vo.TeaOwnInfo;
import com.marchsoft.vo.TeacherExtra;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Component
public interface TeacherMapper extends CommentMapper<Teacher> {

    /**
     * 根据小组id查询导师
     * @param gid
     * @return
     */
    @Select("SELECT * FROM teacher WHERE group_id=#{gid}")
    @Results({
            @Result(id=true,column="group_id",property="groupId"),
    })
    List<Teacher> queryTeacherInfo(Integer gid);

    /**
     * 查询导师id 及其当前团队人数
     * @return
     */
    @Select("SELECT t.tid Tid,count(s.sid) number FROM teacher t ,student s WHERE  t.tid = s.tid OR s.tid=0 group by s.tid")
    @Results({
            @Result(column="Tid",property="tid"),
            @Result(column = "number",property = "stuNumber")
    })
    List<TeacherExtra> queryTeaTeamPeoples();

    /**
     * 根据tid查询导师的当前团队人数
     *
     * @param tid 导师id
     * @return
     */
    @Select("SELECT t.tid Tid,count(s.sid) number FROM teacher t ,student s WHERE  t.tid = s.tid AND t.tid=#{tid} group by s.tid")
    @Results({
            @Result(column="Tid",property="tid"),
            @Result(column = "number",property = "stuNumber")
    })
    TeacherExtra queryTeaTeamPeople(Integer tid);

    /**
     *根据tid查询导师的个人信息
     * @param tid
     * @return
     */
    @Select("SELECT t.tid id,t.name name,p.account number,t.major major,t.email email FROM teacher t,account_pass p WHERE t.zid = p.zid AND t.tid = #{tid}")
    TeaOwnInfo queryOwnInfo(Integer tid);
}